import xlrd
# filename=r"C:\Users\Administrator\Downloads\ddt_testwoniusales.xls"
# wb=xlrd.open_workbook(filename)  # 打开excel文件【后缀名是xls的文件】
# sheet1=wb.sheet_by_name("Sheet1")  # 通过名字取sheet。
# # wb.sheet_by_index(0)  #通过sheet的下标取
# # 拿到行数
# nrows=sheet1.nrows
# list = []
# for r in range(nrows):
#     r_values=sheet1.row_values(r)  # 取行数据，参数0为第一行。
#     if r != 0:
#         a= dict(zip(sheet1.row_values(0),r_values))
#         list.append(a)
# print(list)

class Readxls(object):
    def __init__(self,filename=r"C:\Users\Administrator\Downloads\ddt_testwoniusales.xls",sheet='Sheet1'):
        self.file = filename
        self.sheet = sheet
        self.list = []
    def readxls(self):
        wb = xlrd.open_workbook(self.file)
        mysheet = wb.sheet_by_name(self.sheet)
        for r in range(mysheet.nrows):
            r_values = mysheet.row_values(r)  # 取行数据，参数0为第一行。
            if r != 0:
                a = dict(zip(mysheet.row_values(0), r_values))
                self.list.append(a)
        return self.list

if __name__ == '__main__':
    r1=Readxls()
    print(r1.readxls())
